﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Admin.Models.User;
using Zocono.WCS.Application.AppTraces;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.Admin.Controllers.LogMoudle
{
    public class UserLogController : BaseController
    {
        private readonly TracesApp _TracesApp;

        public UserLogController(IMemoryCache memoryCache, TracesApp tracesApp, IHttpContextAccessor httpContextAccessor) : base(memoryCache, tracesApp, httpContextAccessor)
        {
            _TracesApp = tracesApp;
        }
        public IActionResult Index()
        {
            return View();
        }
        public async Task<ActionResult> UserLogAsync()
        {
            TracesInfoDto tracesInfo = new TracesInfoDto();
            var res= await  _TracesApp.GetTracesAsync(tracesInfo);
            return View(res);
        }

        /// <summary>
        /// 获取用户操作列表
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> GetAllTracesInfoAsync()
        {
            TracesInfoDto tracesInfo = new TracesInfoDto();
            tracesInfo.PageIndex = (Start / Length) + 1;
            tracesInfo.PageSize = Length;
            var username=Request.Form["UserName"].ToString();
            var operationType = Request.Form["OperationType"].ToInt32();
            tracesInfo.UserName=username;
            tracesInfo.OperationType=operationType;
            tracesInfo.StarTime = Request.Form["startTime"];
            tracesInfo.EndTime = Request.Form["endTime"];
            var res= await _TracesApp.GetTracesAsync(tracesInfo);
            var pageData = new TableData<TracesInfoDto>(Draw, res.Total, res.Total, res.Result);
            return Json(pageData);
        }
    }
}
